//axios 的封装

import axios from 'axios';
//配置
const service = axios.create({
    baseURL: '/',//基础路径
    timeout: 60000 //请求的超时时间
})

//请求拦截
service.interceptors.request.use(
    config => {
        //配置头部的token
        return config;
    },
    err => {
        console.log("请求出错", err);
    }
)

//响应拦截
service.interceptors.response.use(
    data => {
        //需要有后台的文档支持
        return data;
    },
    err => {//响应时出错
        console.log(err.response.status);
        const status = err.response.status;
        if (status === 404) {
            console.log("页面没找到");
        } else if (status === 500) {
            console.log("服务器端错误");
        } else {
            console.log("请求出错");
        }

    }
)

export default service;